vulkan: Make the effect renderer take matrix + offset
authorBenjamin Otte <otte@redhat.com>
Sat, 31 Dec 2016 12:24:21 +0000 (13:24 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 31 Dec 2016 13:37:20 +0000 (14:37 +0100)
This is in preparation for the new color matrix node.

I don't think keeping support for a separate opacity shader is worth it.

29 files changed:
gsk/gskvulkaneffectpipeline.c
gsk/gskvulkaneffectpipelineprivate.h
gsk/gskvulkanrender.c
gsk/gskvulkanrenderpass.c
gsk/gskvulkanrenderprivate.h
gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip.frag.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip.frag.spv [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip.vert.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix-clip.vert.spv [new file with mode: 0644]
gsk/resources/vulkan/color-matrix.frag.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix.frag.spv [new file with mode: 0644]
gsk/resources/vulkan/color-matrix.vert.glsl [new file with mode: 0644]
gsk/resources/vulkan/color-matrix.vert.spv [new file with mode: 0644]
gsk/resources/vulkan/opacity-clip-rounded.frag.glsl [deleted file]
gsk/resources/vulkan/opacity-clip-rounded.frag.spv [deleted file]
gsk/resources/vulkan/opacity-clip-rounded.vert.glsl [deleted file]
gsk/resources/vulkan/opacity-clip-rounded.vert.spv [deleted file]
gsk/resources/vulkan/opacity-clip.frag.glsl [deleted file]
gsk/resources/vulkan/opacity-clip.frag.spv [deleted file]
gsk/resources/vulkan/opacity-clip.vert.glsl [deleted file]
gsk/resources/vulkan/opacity-clip.vert.spv [deleted file]
gsk/resources/vulkan/opacity.frag.glsl [deleted file]
gsk/resources/vulkan/opacity.frag.spv [deleted file]
gsk/resources/vulkan/opacity.vert.glsl [deleted file]
gsk/resources/vulkan/opacity.vert.spv [deleted file]

index 249185c1cf395d2ff747e8dc07ca47bd7a337f92..8572da56dca26c712537751968d024ce0a3ef22a 100644 (file)
@@ -13,7 +13,8 @@ struct _GskVulkanEffectInstance
 {
   float rect[4];
   float tex_rect[4];
-  float value;
+  float color_matrix[16];
+  float color_offset[4];
 };
 
 G_DEFINE_TYPE (GskVulkanEffectPipeline, gsk_vulkan_effect_pipeline, GSK_TYPE_VULKAN_PIPELINE)
@@ -45,7 +46,31 @@ gsk_vulkan_effect_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
           .location = 2,
           .binding = 0,
           .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, value),
+          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix),
+      },
+      {
+          .location = 3,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 4,
+      },
+      {
+          .location = 4,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 8,
+      },
+      {
+          .location = 5,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 12,
+      },
+      {
+          .location = 6,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_offset),
       }
   };
   static const VkPipelineVertexInputStateCreateInfo info = {
@@ -100,7 +125,8 @@ void
 gsk_vulkan_effect_pipeline_collect_vertex_data (GskVulkanEffectPipeline *pipeline,
                                                 guchar                  *data,
                                                 const graphene_rect_t   *rect,
-                                                float                    value)
+                                                const graphene_matrix_t *color_matrix,
+                                                const graphene_vec4_t   *color_offset)
 {
   GskVulkanEffectInstance *instance = (GskVulkanEffectInstance *) data;
 
@@ -112,7 +138,8 @@ gsk_vulkan_effect_pipeline_collect_vertex_data (GskVulkanEffectPipeline *pipelin
   instance->tex_rect[1] = 0.0;
   instance->tex_rect[2] = 1.0;
   instance->tex_rect[3] = 1.0;
-  instance->value = value;
+  graphene_matrix_to_float (color_matrix, instance->color_matrix);
+  graphene_vec4_to_float (color_offset, instance->color_offset);
 }
 
 gsize
index 9a82c0242e8230f1a5656a9abda7ccce79329394..d2bff8105c33228b4bc8dfdd070302ba67e9cf93 100644 (file)
@@ -21,7 +21,8 @@ gsize                   gsk_vulkan_effect_pipeline_count_vertex_data    (GskVulk
 void                    gsk_vulkan_effect_pipeline_collect_vertex_data  (GskVulkanEffectPipeline        *pipeline,
                                                                          guchar                         *data,
                                                                          const graphene_rect_t          *rect,
-                                                                         float                           value);
+                                                                         const graphene_matrix_t        *color_matrix,
+                                                                         const graphene_vec4_t          *color_offset);
 gsize                   gsk_vulkan_effect_pipeline_draw                 (GskVulkanEffectPipeline        *pipeline,
                                                                          VkCommandBuffer                 command_buffer,
                                                                          gsize                           offset,
index 81bc3193b5438268faa428f9054a39089c1f742f..35e2dce29587e9ebb76e910ee09428d99389d5a6 100644 (file)
@@ -321,9 +321,9 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
     { "linear", gsk_vulkan_linear_gradient_pipeline_new },
     { "linear-clip", gsk_vulkan_linear_gradient_pipeline_new },
     { "linear-clip-rounded", gsk_vulkan_linear_gradient_pipeline_new },
-    { "opacity", gsk_vulkan_effect_pipeline_new },
-    { "opacity-clip", gsk_vulkan_effect_pipeline_new },
-    { "opacity-clip-rounded", gsk_vulkan_effect_pipeline_new }
+    { "color-matrix", gsk_vulkan_effect_pipeline_new },
+    { "color-matrix-clip", gsk_vulkan_effect_pipeline_new },
+    { "color-matrix-clip-rounded", gsk_vulkan_effect_pipeline_new }
   };
 
   g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
index 70f1de35c5c8837976dcaffc879115bfe09e79eb..b005607423fb3ccb1174e6b7e83ded7e33c2660e 100644 (file)
@@ -171,11 +171,11 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass           *self,
 
     case GSK_OPACITY_NODE:
       if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
-        pipeline_type = GSK_VULKAN_PIPELINE_OPACITY;
+        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_MATRIX;
       else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
-        pipeline_type = GSK_VULKAN_PIPELINE_OPACITY_CLIP;
+        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_MATRIX_CLIP;
       else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
-        pipeline_type = GSK_VULKAN_PIPELINE_OPACITY_CLIP_ROUNDED;
+        pipeline_type = GSK_VULKAN_PIPELINE_COLOR_MATRIX_CLIP_ROUNDED;
       else
         FALLBACK ("Opacity nodes can't deal with clip type %u\n", constants->clip.type);
       op.type = GSK_VULKAN_OP_OPACITY;
@@ -554,11 +554,22 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
 
         case GSK_VULKAN_OP_OPACITY:
           {
+            graphene_matrix_t color_matrix;
+            graphene_vec4_t color_offset;
+            graphene_matrix_init_from_float (&color_matrix,
+                                             (float[16]) {
+                                                 1.0, 0.0, 0.0, 0.0,         
+                                                 0.0, 1.0, 0.0, 0.0,         
+                                                 0.0, 0.0, 1.0, 0.0,         
+                                                 0.0, 0.0, 0.0, gsk_opacity_node_get_opacity (op->render.node)
+                                             });
+            graphene_vec4_init (&color_offset, 0.0, 0.0, 0.0, 0.0);
             op->render.vertex_offset = offset + n_bytes;
             gsk_vulkan_effect_pipeline_collect_vertex_data (GSK_VULKAN_EFFECT_PIPELINE (op->render.pipeline),
                                                             data + n_bytes + offset,
                                                             &op->render.node->bounds,
-                                                            gsk_opacity_node_get_opacity (op->render.node));
+                                                            &color_matrix,
+                                                            &color_offset);
             n_bytes += op->render.vertex_count;
           }
           break;
index 6de38d27470c9f3dfe458fe8bbb69f235b5110af..cffce7f0c5dd2df9a396cc2503505befdd196d5e 100644 (file)
@@ -17,9 +17,9 @@ typedef enum {
   GSK_VULKAN_PIPELINE_LINEAR_GRADIENT,
   GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP,
   GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP_ROUNDED,
-  GSK_VULKAN_PIPELINE_OPACITY,
-  GSK_VULKAN_PIPELINE_OPACITY_CLIP,
-  GSK_VULKAN_PIPELINE_OPACITY_CLIP_ROUNDED,
+  GSK_VULKAN_PIPELINE_COLOR_MATRIX,
+  GSK_VULKAN_PIPELINE_COLOR_MATRIX_CLIP,
+  GSK_VULKAN_PIPELINE_COLOR_MATRIX_CLIP_ROUNDED,
   /* add more */
   GSK_VULKAN_N_PIPELINES
 } GskVulkanPipelineType;
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
new file mode 100644 (file)
index 0000000..c0e42ca
--- /dev/null
@@ -0,0 +1,76 @@
+#version 420 core
+
+struct RoundedRect {
+  vec4 bounds;
+  vec4 corners;
+};
+
+layout(location = 0) in vec2 inPos;
+layout(location = 1) in vec2 inTexCoord;
+layout(location = 2) in flat vec4 inClipBounds;
+layout(location = 3) in flat vec4 inClipWidths;
+layout(location = 4) in flat mat4 inColorMatrix;
+layout(location = 8) in flat vec4 inColorOffset;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+float clip(vec2 pos, RoundedRect r) {
+  vec2 ref_tl = r.bounds.xy + vec2( r.corners.x,  r.corners.x);
+  vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y,  r.corners.y);
+  vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
+  vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
+  
+  float d_tl = distance(pos, ref_tl);
+  float d_tr = distance(pos, ref_tr);
+  float d_br = distance(pos, ref_br);
+  float d_bl = distance(pos, ref_bl);
+
+  float pixels_per_fragment = length(fwidth(pos.xy));
+  float nudge = 0.5 * pixels_per_fragment;
+  vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
+
+  bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
+                       pos.x > ref_tr.x && pos.y < ref_tr.y,
+                       pos.x > ref_br.x && pos.y > ref_br.y,
+                       pos.x < ref_bl.x && pos.y > ref_bl.y);
+
+  float distance_from_border = dot(vec4(is_out),
+                                   max(vec4(0.0, 0.0, 0.0, 0.0), distances));
+
+  // Move the distance back into pixels.
+  distance_from_border /= pixels_per_fragment;
+  // Apply a more gradual fade out to transparent.
+  //distance_from_border -= 0.5;
+
+  return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
+}
+
+vec4
+color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
+{
+  /* unpremultiply */
+  if (color.a != 0.0)
+    color.rgb /= color.a;
+
+  color = color_matrix * color + color_offset;
+  color = clamp(color, 0.0, 1.0);
+
+  /* premultiply */
+  if (color.a != 0.0)
+    color.rgb *= color.a;
+
+  return color;
+}
+
+void main()
+{
+  RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
+
+  color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset) * clip (inPos, r);
+}
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv
new file mode 100644 (file)
index 0000000..f4c753a
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl
new file mode 100644 (file)
index 0000000..2875e63
--- /dev/null
@@ -0,0 +1,59 @@
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+layout(location = 2) in mat4 inColorMatrix;
+layout(location = 6) in vec4 inColorOffset;
+
+layout(push_constant) uniform PushConstants {
+    mat4 mvp;
+    vec4 clip_bounds;
+    vec4 clip_widths;
+    vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outPos;
+layout(location = 1) out vec2 outTexCoord;
+layout(location = 2) out flat vec4 outClipBounds;
+layout(location = 3) out flat vec4 outClipWidths;
+layout(location = 4) out flat mat4 outColorMatrix;
+layout(location = 8) out flat vec4 outColorOffset;
+
+out gl_PerVertex {
+  vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+                    vec2(1.0, 0.0),
+                    vec2(0.0, 1.0),
+                    vec2(0.0, 1.0),
+                    vec2(1.0, 0.0),
+                    vec2(1.0, 1.0) };
+
+vec4 intersect(vec4 a, vec4 b)
+{
+  a = vec4(a.xy, a.xy + a.zw);
+  b = vec4(b.xy, b.xy + b.zw);
+  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+  if (any (greaterThanEqual (result.xy, result.zw)))
+    return vec4(0.0,0.0,0.0,0.0);
+  return vec4(result.xy, result.zw - result.xy);
+}
+
+void main() {
+  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
+  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+  outPos = pos;
+  outClipBounds = push.clip_bounds;
+  outClipWidths = push.clip_widths;
+
+  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
+                      rect.zw / inRect.zw);
+  texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
+                 inTexRect.zw * texrect.zw);
+  outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
+  outColorMatrix = inColorMatrix;
+  outColorOffset = inColorOffset;
+}
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv
new file mode 100644 (file)
index 0000000..49271e4
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip.frag.glsl b/gsk/resources/vulkan/color-matrix-clip.frag.glsl
new file mode 100644 (file)
index 0000000..21a324e
--- /dev/null
@@ -0,0 +1,31 @@
+#version 420 core
+
+layout(location = 0) in vec2 inTexCoord;
+layout(location = 1) in flat mat4 inColorMatrix;
+layout(location = 5) in flat vec4 inColorOffset;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+vec4
+color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
+{
+  /* unpremultiply */
+  if (color.a != 0.0)
+    color.rgb /= color.a;
+
+  color = color_matrix * color + color_offset;
+  color = clamp(color, 0.0, 1.0);
+
+  /* premultiply */
+  if (color.a != 0.0)
+    color.rgb *= color.a;
+
+  return color;
+}
+
+void main()
+{
+  color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset);
+}
diff --git a/gsk/resources/vulkan/color-matrix-clip.frag.spv b/gsk/resources/vulkan/color-matrix-clip.frag.spv
new file mode 100644 (file)
index 0000000..266c877
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix-clip.frag.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.glsl b/gsk/resources/vulkan/color-matrix-clip.vert.glsl
new file mode 100644 (file)
index 0000000..94d4ef8
--- /dev/null
@@ -0,0 +1,52 @@
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+layout(location = 2) in mat4 inColorMatrix;
+layout(location = 6) in vec4 inColorOffset;
+
+layout(push_constant) uniform PushConstants {
+    mat4 mvp;
+    vec4 clip_bounds;
+    vec4 clip_widths;
+    vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outTexCoord;
+layout(location = 1) out flat mat4 outColorMatrix;
+layout(location = 5) out flat vec4 outColorOffset;
+
+out gl_PerVertex {
+  vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+                    vec2(1.0, 0.0),
+                    vec2(0.0, 1.0),
+                    vec2(0.0, 1.0),
+                    vec2(1.0, 0.0),
+                    vec2(1.0, 1.0) };
+
+vec4 intersect(vec4 a, vec4 b)
+{
+  a = vec4(a.xy, a.xy + a.zw);
+  b = vec4(b.xy, b.xy + b.zw);
+  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
+  if (any (greaterThanEqual (result.xy, result.zw)))
+    return vec4(0.0,0.0,0.0,0.0);
+  return vec4(result.xy, result.zw - result.xy);
+}
+
+void main() {
+  vec4 rect = intersect(inRect, push.clip_bounds);
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
+  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
+                      rect.zw / inRect.zw);
+  texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
+                 inTexRect.zw * texrect.zw);
+  outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
+  outColorMatrix = inColorMatrix;
+  outColorOffset = inColorOffset;
+}
diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.spv b/gsk/resources/vulkan/color-matrix-clip.vert.spv
new file mode 100644 (file)
index 0000000..6648e24
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/color-matrix.frag.glsl b/gsk/resources/vulkan/color-matrix.frag.glsl
new file mode 100644 (file)
index 0000000..21a324e
--- /dev/null
@@ -0,0 +1,31 @@
+#version 420 core
+
+layout(location = 0) in vec2 inTexCoord;
+layout(location = 1) in flat mat4 inColorMatrix;
+layout(location = 5) in flat vec4 inColorOffset;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+vec4
+color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
+{
+  /* unpremultiply */
+  if (color.a != 0.0)
+    color.rgb /= color.a;
+
+  color = color_matrix * color + color_offset;
+  color = clamp(color, 0.0, 1.0);
+
+  /* premultiply */
+  if (color.a != 0.0)
+    color.rgb *= color.a;
+
+  return color;
+}
+
+void main()
+{
+  color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset);
+}
diff --git a/gsk/resources/vulkan/color-matrix.frag.spv b/gsk/resources/vulkan/color-matrix.frag.spv
new file mode 100644 (file)
index 0000000..266c877
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix.frag.spv differ
diff --git a/gsk/resources/vulkan/color-matrix.vert.glsl b/gsk/resources/vulkan/color-matrix.vert.glsl
new file mode 100644 (file)
index 0000000..20b3bbd
--- /dev/null
@@ -0,0 +1,37 @@
+#version 420 core
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+layout(location = 2) in mat4 inColorMatrix;
+layout(location = 6) in vec4 inColorOffset;
+
+layout(push_constant) uniform PushConstants {
+    mat4 mvp;
+    vec4 clip_bounds;
+    vec4 clip_widths;
+    vec4 clip_heights;
+} push;
+
+layout(location = 0) out vec2 outTexCoord;
+layout(location = 1) out flat mat4 outColorMatrix;
+layout(location = 5) out flat vec4 outColorOffset;
+
+out gl_PerVertex {
+  vec4 gl_Position;
+};
+
+vec2 offsets[6] = { vec2(0.0, 0.0),
+                    vec2(1.0, 0.0),
+                    vec2(0.0, 1.0),
+                    vec2(0.0, 1.0),
+                    vec2(1.0, 0.0),
+                    vec2(1.0, 1.0) };
+
+void main() {
+  vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
+  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+  outTexCoord = inTexRect.xy + inTexRect.zw * offsets[gl_VertexIndex];
+  outColorMatrix = inColorMatrix;
+  outColorOffset = inColorOffset;
+}
diff --git a/gsk/resources/vulkan/color-matrix.vert.spv b/gsk/resources/vulkan/color-matrix.vert.spv
new file mode 100644 (file)
index 0000000..2985b74
Binary files /dev/null and b/gsk/resources/vulkan/color-matrix.vert.spv differ
diff --git a/gsk/resources/vulkan/opacity-clip-rounded.frag.glsl b/gsk/resources/vulkan/opacity-clip-rounded.frag.glsl
deleted file mode 100644 (file)
index 91c1e54..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-#version 420 core
-
-struct RoundedRect {
-  vec4 bounds;
-  vec4 corners;
-};
-
-layout(location = 0) in vec2 inPos;
-layout(location = 1) in vec2 inTexCoord;
-layout(location = 2) in flat float inOpacity;
-layout(location = 3) in flat vec4 inClipBounds;
-layout(location = 4) in flat vec4 inClipWidths;
-
-layout(set = 0, binding = 0) uniform sampler2D inTexture;
-
-layout(location = 0) out vec4 color;
-
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-float clip(vec2 pos, RoundedRect r) {
-  vec2 ref_tl = r.bounds.xy + vec2( r.corners.x,  r.corners.x);
-  vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y,  r.corners.y);
-  vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
-  vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
-  
-  float d_tl = distance(pos, ref_tl);
-  float d_tr = distance(pos, ref_tr);
-  float d_br = distance(pos, ref_br);
-  float d_bl = distance(pos, ref_bl);
-
-  float pixels_per_fragment = length(fwidth(pos.xy));
-  float nudge = 0.5 * pixels_per_fragment;
-  vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
-
-  bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
-                       pos.x > ref_tr.x && pos.y < ref_tr.y,
-                       pos.x > ref_br.x && pos.y > ref_br.y,
-                       pos.x < ref_bl.x && pos.y > ref_bl.y);
-
-  float distance_from_border = dot(vec4(is_out),
-                                   max(vec4(0.0, 0.0, 0.0, 0.0), distances));
-
-  // Move the distance back into pixels.
-  distance_from_border /= pixels_per_fragment;
-  // Apply a more gradual fade out to transparent.
-  //distance_from_border -= 0.5;
-
-  return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
-}
-
-vec4
-opacity (vec4 color, float value)
-{
-  return color * value;
-}
-
-void main()
-{
-  RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
-
-  color = opacity (texture (inTexture, inTexCoord), inOpacity) * clip (inPos, r);
-}
diff --git a/gsk/resources/vulkan/opacity-clip-rounded.frag.spv b/gsk/resources/vulkan/opacity-clip-rounded.frag.spv
deleted file mode 100644 (file)
index 42fa156..0000000
Binary files a/gsk/resources/vulkan/opacity-clip-rounded.frag.spv and /dev/null differ
diff --git a/gsk/resources/vulkan/opacity-clip-rounded.vert.glsl b/gsk/resources/vulkan/opacity-clip-rounded.vert.glsl
deleted file mode 100644 (file)
index 5f0b898..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#version 420 core
-
-layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inTexRect;
-layout(location = 2) in float inOpacity;
-
-layout(push_constant) uniform PushConstants {
-    mat4 mvp;
-    vec4 clip_bounds;
-    vec4 clip_widths;
-    vec4 clip_heights;
-} push;
-
-layout(location = 0) out vec2 outPos;
-layout(location = 1) out vec2 outTexCoord;
-layout(location = 2) out flat float outOpacity;
-layout(location = 3) out flat vec4 outClipBounds;
-layout(location = 4) out flat vec4 outClipWidths;
-
-out gl_PerVertex {
-  vec4 gl_Position;
-};
-
-vec2 offsets[6] = { vec2(0.0, 0.0),
-                    vec2(1.0, 0.0),
-                    vec2(0.0, 1.0),
-                    vec2(0.0, 1.0),
-                    vec2(1.0, 0.0),
-                    vec2(1.0, 1.0) };
-
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
-void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
-  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
-  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
-
-  outPos = pos;
-  outClipBounds = push.clip_bounds;
-  outClipWidths = push.clip_widths;
-
-  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
-                      rect.zw / inRect.zw);
-  texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
-                 inTexRect.zw * texrect.zw);
-  outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
-  outOpacity = inOpacity;
-}
diff --git a/gsk/resources/vulkan/opacity-clip-rounded.vert.spv b/gsk/resources/vulkan/opacity-clip-rounded.vert.spv
deleted file mode 100644 (file)
index 1090dab..0000000
Binary files a/gsk/resources/vulkan/opacity-clip-rounded.vert.spv and /dev/null differ
diff --git a/gsk/resources/vulkan/opacity-clip.frag.glsl b/gsk/resources/vulkan/opacity-clip.frag.glsl
deleted file mode 100644 (file)
index 7ff7d34..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#version 420 core
-
-layout(location = 0) in vec2 inTexCoord;
-layout(location = 1) in flat float inOpacity;
-
-layout(set = 0, binding = 0) uniform sampler2D inTexture;
-
-layout(location = 0) out vec4 color;
-
-vec4
-opacity (vec4 color, float value)
-{
-  return color * value;
-}
-
-void main()
-{
-  color = opacity (texture (inTexture, inTexCoord), inOpacity);
-}
diff --git a/gsk/resources/vulkan/opacity-clip.frag.spv b/gsk/resources/vulkan/opacity-clip.frag.spv
deleted file mode 100644 (file)
index 5729abe..0000000
Binary files a/gsk/resources/vulkan/opacity-clip.frag.spv and /dev/null differ
diff --git a/gsk/resources/vulkan/opacity-clip.vert.glsl b/gsk/resources/vulkan/opacity-clip.vert.glsl
deleted file mode 100644 (file)
index 4cf0f13..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#version 420 core
-
-layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inTexRect;
-layout(location = 2) in float inOpacity;
-
-layout(push_constant) uniform PushConstants {
-    mat4 mvp;
-    vec4 clip_bounds;
-    vec4 clip_widths;
-    vec4 clip_heights;
-} push;
-
-layout(location = 0) out vec2 outTexCoord;
-layout(location = 1) out flat float outOpacity;
-
-out gl_PerVertex {
-  vec4 gl_Position;
-};
-
-vec2 offsets[6] = { vec2(0.0, 0.0),
-                    vec2(1.0, 0.0),
-                    vec2(0.0, 1.0),
-                    vec2(0.0, 1.0),
-                    vec2(1.0, 0.0),
-                    vec2(1.0, 1.0) };
-
-vec4 intersect(vec4 a, vec4 b)
-{
-  a = vec4(a.xy, a.xy + a.zw);
-  b = vec4(b.xy, b.xy + b.zw);
-  vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
-  if (any (greaterThanEqual (result.xy, result.zw)))
-    return vec4(0.0,0.0,0.0,0.0);
-  return vec4(result.xy, result.zw - result.xy);
-}
-
-void main() {
-  vec4 rect = intersect(inRect, push.clip_bounds);
-  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
-  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
-
-  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
-                      rect.zw / inRect.zw);
-  texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
-                 inTexRect.zw * texrect.zw);
-  outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
-  outOpacity = inOpacity;
-}
diff --git a/gsk/resources/vulkan/opacity-clip.vert.spv b/gsk/resources/vulkan/opacity-clip.vert.spv
deleted file mode 100644 (file)
index 81aa4f6..0000000
Binary files a/gsk/resources/vulkan/opacity-clip.vert.spv and /dev/null differ
diff --git a/gsk/resources/vulkan/opacity.frag.glsl b/gsk/resources/vulkan/opacity.frag.glsl
deleted file mode 100644 (file)
index 7ff7d34..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#version 420 core
-
-layout(location = 0) in vec2 inTexCoord;
-layout(location = 1) in flat float inOpacity;
-
-layout(set = 0, binding = 0) uniform sampler2D inTexture;
-
-layout(location = 0) out vec4 color;
-
-vec4
-opacity (vec4 color, float value)
-{
-  return color * value;
-}
-
-void main()
-{
-  color = opacity (texture (inTexture, inTexCoord), inOpacity);
-}
diff --git a/gsk/resources/vulkan/opacity.frag.spv b/gsk/resources/vulkan/opacity.frag.spv
deleted file mode 100644 (file)
index 5729abe..0000000
Binary files a/gsk/resources/vulkan/opacity.frag.spv and /dev/null differ
diff --git a/gsk/resources/vulkan/opacity.vert.glsl b/gsk/resources/vulkan/opacity.vert.glsl
deleted file mode 100644 (file)
index 7e12d41..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#version 420 core
-
-layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inTexRect;
-layout(location = 2) in float inOpacity;
-
-layout(push_constant) uniform PushConstants {
-    mat4 mvp;
-    vec4 clip_bounds;
-    vec4 clip_widths;
-    vec4 clip_heights;
-} push;
-
-layout(location = 0) out vec2 outTexCoord;
-layout(location = 1) out flat float outOpacity;
-
-out gl_PerVertex {
-  vec4 gl_Position;
-};
-
-vec2 offsets[6] = { vec2(0.0, 0.0),
-                    vec2(1.0, 0.0),
-                    vec2(0.0, 1.0),
-                    vec2(0.0, 1.0),
-                    vec2(1.0, 0.0),
-                    vec2(1.0, 1.0) };
-
-void main() {
-  vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex];
-  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
-
-  outTexCoord = inTexRect.xy + inTexRect.zw * offsets[gl_VertexIndex];
-  outOpacity = inOpacity;
-}
diff --git a/gsk/resources/vulkan/opacity.vert.spv b/gsk/resources/vulkan/opacity.vert.spv
deleted file mode 100644 (file)
index d0c9b86..0000000
Binary files a/gsk/resources/vulkan/opacity.vert.spv and /dev/null differ